<?php
class Comment extends AppModel {

    public $recursive = -1;
    public $name = 'Comment';
    public $actsAs = array(
        'Switchable' => array(
            'fileds' => array('approved')
        ),
    );
    public $validate = array(
        'content' => array('notempty'),
        'client' => array('notempty'),
        'post_id' => array('notempty'),
        'user_id' => array('notempty')
    );

    // the Associations below have been created with all possible keys,
    // those that are not needed can be removed
    public $belongsTo = array(
        'Post' => array(
            'className' => 'Post',
            'foreignKey' => 'post_id',
            'counterCache' => true,
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

    /* Get last inseted comment via ajax,  */
    public function getLastComment(){
        $comment = $this->find('first', array(
            'conditions' => array('Comment.id'=>$this->getLastInsertId()),
            'contain' => array('User')
            )
        );
        return $comment;
    }

}
?>